package com.run2code.controller;

import com.alibaba.fastjson.JSON;
import com.run2code.dto.BizTestParamDto;
import com.run2code.log.annotation.BizLog;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 测试Controller层入口
 * 关注公众号【奔跑的码畜】，一起进步不迷路
 *
 * @author 第七人格
 * @date 2023/10/12
 */
@RestController
@RequestMapping("/http")
@Slf4j
public class BizController {

    @GetMapping("/testBizGet/{param}")
    @BizLog(
            module = "测试模块",
            type = "查询",
            operator = "{{#_result}}",
            success = "[{{#_result}}]请求get测试接口，参数内容为[{{#param}}]，请求后的内容参数为[{getAfterResultDemo{#param}}]"
    )
    public String testBizGet(@PathVariable(value = "param") String param){
        log.info("入参：{}",param);
        return "第七人格";
    }

    @PostMapping("/testBizPost")
    @BizLog(
            module = "测试模块",
            type = "查询",
            bizNo = "{{#param.param}}",
            operator = "{{#param.operator}}",
            success = "用户：[{{#param.operator}}-{{#param.operator}}]，请求post测试接口，参数内容为[{{#param.param}}]",
            condition = "{{#param.operator == '第七人格'}}"
    )
    public String testBizPost(@RequestBody BizTestParamDto param){
        String result = JSON.toJSONString(param);
        log.info("入参：{}", result);
        return "这是post的返回结果："+result;
    }

}
